package com.populatton.base;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;

/**
 * @创建人 shmily
 * @Date 2019/7/9
 * @描述
 */

@Data
@JsonIgnoreProperties(ignoreUnknown=true)
@Slf4j
public class BaseWrappers<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private int code=0;
    private String message="";
    private T data;



    public static BaseWrappers<Integer> SUCCESS  = new BaseWrappers<Integer>();

    public BaseWrappers(){
        this(RespEnum.SUCCESS);
    }

    public BaseWrappers(RespEnum bw){
        this(bw.getCode(),bw.getDesc());
    }

    public BaseWrappers(RespEnum bw, String message, T data){
        this(bw.getCode(),message,data);
    }

    public BaseWrappers(int code, String message) {
        this(code,message,null);
    }

    public BaseWrappers(RespEnum bw, String message){
        this(bw.getCode(),message);
    }

    public BaseWrappers(RespEnum bw, T data){
        this(bw.getCode(), bw.getDesc(),data);
    }


    /**
     * 判断查询对象是否为null
     * @param  data;
     */
    public BaseWrappers(T data) {
        this( RespEnum.SUCCESS.getCode(),RespEnum.SUCCESS.getDesc(),data);
    }

    /**
     * 判断查询对象是否为null
     * @param  data;
     */
    public BaseWrappers(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
        if(log.isInfoEnabled()){
            log.info(JSONObject.toJSONString(this));
        }
    }

}
